<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/5/30 0030
  Time: 上午 9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--<%@ include file="/WEB-INF/views/modules/common/treeview.jsp" %>--%>
<html>
<head>
    <link href="${ctxStatic}/common/css/zTreeStyle.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="${ctxStatic}/common/js/jquery.ztree.all-3.5.js"></script>
    <script>
        var nodes = [];
        function treeSelect(url,name) {
            $(".modal-title").html(name);
            $('#myModal').modal({
                keyboard: true
            })
        }
        var tree, setting = {
            async: {
                enable: true,
                url: "${ctx}/resource/basic/department/treeData"
            },
            data: {
                simpleData: {
                    enable: true,
                    idKey : "id",
                    pIdKey : "pId",
                    rootPId : -1
                }
            },
            callback: {
                // zTree单击事件
                onClick: function (event, treeId, treeNode) {
                    nodes = tree.getSelectedNodes();
                },
                // zTree加载完成事件
                onAsyncSuccess: function () {
                }
            }
        };
        function save() {
            if(nodes.length>0){
                var node = nodes[0];
                $("#labelId").val(node.id);
                $("#labelName").val(node.name);
                $('#myModal').modal('hide');
            }
        }
        $(function () {
            // 初始化树结构
            tree = $.fn.zTree.init($("#tree"), setting);
        })
    </script>
</head>
<body>
    <div class="modal fade" id="myModal">
        <div class="modal-dialog" style="width: 400px;height: 200px">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Modal title</h4>
                </div>
                <div class="modal-body">
                    <div id="tree" class="ztree"></div>
                </div>
                <div class="modal-footer" style="height: 50px;padding: 5px">
                    <button type="button" class="btn btn-sm btn-default"  data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-sm btn-primary" onclick="save()">确定</button>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
